package com.itheima.commons;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.exception.BusinessException;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class PageBeanResult<T> implements Serializable {
    private long pageNum;
    private long pageSize;
    private long total;
    private long totalPage;

    private List<T> list;

    public PageBeanResult() {
    }

    public PageBeanResult(IPage<T> page) {
        List<T> records = page.getRecords();
        if (ObjectUtil.isEmpty(records)) {
            throw new BusinessException("暂无数据");
        }
        this.pageSize = page.getCurrent();
        this.pageNum = page.getSize();
        this.total = page.getTotal();
        this.totalPage = page.getPages();
        this.pageSize = page.getSize();
    }
}
